package cz.muni.fi.pa165.musiclibrary.impl.database.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.Type;
import org.joda.time.LocalDate;


/**
*
* @author Radoslav Stefanik 
* @date 2012-10-12T20:27:38+0200
*/
@Entity
@Table(name="album")
public class Album implements Serializable, cz.muni.fi.pa165.musiclibrary.impl.database.entity.IAlbum {
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id_album")
    private Long idAlbum;
    
    @Column(nullable = false)
    private String title;
    
    @Column(name = "release_date")
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
    private LocalDate releaseDate;
    
    @Column(name = "album_art")
    @Lob
    private byte[] albumArt;
    
    @Override
    public Long getIdAlbum() {
        return idAlbum;
    }

    @Override
    public String getTitle() {
        return title;
    }

    @Override
    public LocalDate getReleaseDate() {
        return releaseDate;
    }

    @Override
    public byte[] getAlbumArt() {
        return albumArt; 
    }

    @Override
    public void setIdAlbum(Long idAlbum) {
        this.idAlbum = idAlbum;
    }

    @Override
    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public void setReleaseDate(LocalDate releaseDate) {
        this.releaseDate = releaseDate;
    }

    @Override
    public void setAlbumArt(byte[] albumArt) {
        this.albumArt = albumArt;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idAlbum != null ? idAlbum.hashCode() : 0);
        return hash;
    }
    
    @Override
    public boolean equals(Object object) {
        if (object instanceof Album) {
            return ((IAlbum)object).getIdAlbum() == this.idAlbum;
        } else {
            return false;
        }
        
    }
    
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }
}